﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SkeletonNET.Common.Setup;
using Localizer = SkeletonNET.Localization.Localizer;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using System.Globalization;
using System.ComponentModel.DataAnnotations;
using SkeletonNET.Localizer.Tests;
using System.Linq.Expressions;

namespace SkeletonNET.Localization.Tests
{
    [TestClass]
    public class TestLocalizer
    {
        [TestInitialize]
        public void Initialize()
        {
            Bootstrapper.Current
                .SetupIoC()
                .SetupModules();

            ServiceLocator.Current
                .GetInstance<IUnityContainer>()
                .RegisterType<ILocalizer, InMemoryLocalizer>();
        }

        [TestMethod]
        public void TestMethod1()
        {
            Localizer.Get<InMemoryLocalizer>()
                .AddTranslation(CultureInfo.CurrentUICulture, "test", "test123");
            var test = Localizer.Localize("test");
            Assert.IsTrue(test == "test123");
            Assert.IsTrue(Localizer.Localize<TestEntity>(x => x.Name) == "test123");
        }
    }

    public class InMemoryLocalizer : ILocalizer
    {
        private Dictionary<string, string> Store { get; set; }

        public InMemoryLocalizer()
        {
            Store = new Dictionary<string, string>();
        }

        public string Localize(string inputString, CultureInfo culture)
        {
            string result = string.Empty;
            Store.TryGetValue(inputString, out result);
            return result;
        }

        public ILocalizer AddTranslation(System.Globalization.CultureInfo culture, string identifier, string translation)
        {
            Store.Add(identifier, translation);
            return this;
        }
    }
}
